package cn.edu.stu.syllabus.adapters;

import android.graphics.drawable.GradientDrawable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.application.SyllabusApplication;
import cn.edu.stu.syllabus.base.BaseQuickClickAdapter;
import cn.edu.stu.syllabus.datas.ThemeStyle;
import cn.edu.stu.syllabus.switcher.ThemeStyleSwitcher;

/**
 * Created by daidaijie on 2017/3/8.
 */

public class ThemePickerAdapter extends BaseQuickClickAdapter<ThemeStyle, ThemePickerAdapter.ViewHolder> {

    @Override
    protected ViewHolder createBaseViewHolder(View view) {
        return new ViewHolder(view);
    }

    public ThemePickerAdapter(List<ThemeStyle> data) {
        super(R.layout.item_theme_picker, data);
    }

    @Override
    protected void convert(ViewHolder helper, ThemeStyle item) {
        GradientDrawable shape = (GradientDrawable) ContextCompat
                .getDrawable(SyllabusApplication.getContext(), R.drawable.bg_theme_picker);

        shape.setColor(ContextCompat.getColor(SyllabusApplication.getContext(), item.colorPrimary));
        helper.mThemePickerView.setBackground(shape);
        helper.mShowCurrent.setVisibility(
                item.name.equals(ThemeStyleSwitcher.getInstance().getCurrentThemeStyle().name)
                        ? View.VISIBLE : View.GONE);
    }

    public class ViewHolder extends BaseViewHolder {
        @BindView(R.id.themePickerView)
        View mThemePickerView;
        @BindView(R.id.showCurrent)
        ImageView mShowCurrent;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
